<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <h1>我是index页面，我引用了秘密script文件</h1>
    <input type="text" value="" id="text" width="500px;">
    <input type="button" value="发送消息给全班" id="btn">
    <!-- 引用秘密文件 -->
    <script type="text/javascript" src="/socket.io/socket.io.js"></script>
    <script>
        // 调用io函数 取得socket对象
        var socket = io();
        // 点击按钮之后 发出提问
        document.getElementById("btn").onclick = function(){
            socket.emit("say","你吃了吗");
        }
        socket.on("answer",function(msg){
            console.log("服务器说：" + msg);
        })
    </script>
</body>
</html>